#用户输入，打印商品列表
#让用户输入商品编号购买
#选择后查询余额是否足够，足够则支付，不够则提醒
#用户可随时退出购买，退出时打印用户已购买的商品和余额

#用户输入，打印商品列表
product_list = [
    ('Apple', 5),
    ('Milk', 6),
    ('phone', 8888),
    ('watch', 1200),
]
shopping_list = []
user_salary = input("请输入你的工资：")
if user_salary.isdigit():
    user_salary = int(user_salary)
    while True:
        print("商品如下：")
        for index, item in enumerate(product_list):
            print(index, item)
            #判断是商品编号？还是退出？
        user_choice = input("请输入要购买的商品编号：")
        #2.判断字符串类型
        if user_choice.isdigit():
            user_choice = int(user_choice)
            if user_choice < len(product_list) and user_choice > -1:
                p_item = product_list[user_choice]
                if user_salary >= p_item[1]:
                    shopping_list.append(p_item)
                    user_salary -= p_item[1]
                    print("购买商品", p_item, "成功您的余额为", user_salary, "元！")
                else:
                    print("您的余额为", user_salary, "余额不足以购买此商品，购买失败！")

            else:
                print("没有这个商品哦")
        elif user_choice == "退出":
            print("--------shopping list-------")
            for i in shopping_list:
                print(i)
            exit()
        else:
            print("invalidate！！！")